<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Expires" content="0">
		<meta http-equiv="Pragma" content="no-cache">
		<meta http-equiv="Cache-control" content="no-cache">
		<meta http-equiv="Cache" content="no-cache">
		<meta charset="utf-8">
		
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		
		<title>红外线首件自主检验量测暨</title>
	
		<link rel="stylesheet" href="../layui/css/layui.css"/>
		
	</head>
	<body>
		<fieldset class="layui-elem-field site-demo-button">
			<legend><big><b>红外线首件自主检验量测暨</b></big></legend>
			<div class="layui-fluid layui-form layui-form-pane">
				<div class="layui-col-sm4">
					<label class="layui-form-label">扫描二维码:</label>
					<div class="layui-input-block">
						<input class="layui-input" placeholder="工单号或机台编号" id="qr" type="text"/>
					</div>
				</div>
			</div>
			
		</fieldset>
		
		<fieldset class="layui-elem-field site-demo-button">
			<legend><big><b id="information">当前信息</b></big></legend>
			<div id="DQ" class="layui-fluid layui-form layui-form-pane">
				<div class="layui-col-sm4">
						<label class="layui-form-label">设备编号:</label>
						<div class="layui-input-block">
							<input class="layui-input" readonly=true placeholder="设备编号" id="JiTaiid" type="text"/>
						</div>
				</div>
				<div class="layui-col-sm4">
					<label class="layui-form-label">工单号:</label>
					<div class="layui-input-block">
						<input class="layui-input" readonly=true placeholder="工单号" id="orderid" type="text"/>
					</div>
				</div>
				<div class="layui-row">
					
				</div>
				<div class="layui-col-sm4">
						<label class="layui-form-label">产品型号:</label>
						<div class="layui-input-block">
							<input class="layui-input" readonly=true placeholder="3030" id="ChanPinXingHao" type="text"/>
						</div>
				</div>
				<div class="layui-col-sm4">
						<label class="layui-form-label">检验人员:</label>
						<div class="layui-input-block">
							<input class="layui-input" placeholder="检验人员" id="JianYanPeople" type="text"/>
						</div>
				</div>
				
				</div>
			</div>
		</fieldset>
		
		
		<div class="container">
			<div id="my">
			
			</div>
			<div id="mytable">
			
			</div>
			
				<div align="left" class="layui-form-item">
					
					<button class="layui-btn  layui-btn-radius layui-btn-normal" id="keep">存储</button>
				</div>
				<div align="right" class="layui-form-item">
					程序版本号：v-1.0.4
				</div>
			
		</div>
		<!-- 加载类ui文件 -->
		<link rel="stylesheet" type="text/css" href="../jexcel-master/dist/css/jquery.jexcel.css" />
		<script src="../_vendor/jquery/dist/jquery.min.js"></script>
		<script src="../jexcel-master/dist/js/jquery.jexcel.js"></script>
		<script src="../_vendor/popper.js/dist/umd/popper.min.js"></script>
		<script src="../_vendor/bootstrap/dist/js/bootstrap.min.js"></script>
		<script src="../_assets/js/custom.js"></script>
		<script src="../layui/layui.js"></script>
		<!-- 写脚本 -->
		<script>
		/**
			//这里是画面准备完毕后执行调用layui格式
		*/
			$(document).ready(function(){
				layui.use(['layer','form','element','table'], function(){
					var layer = layui.layer
						,form = layui.form
						,element = layui.element
						,table = layui.table
					;
					layer.msg('初始化正常!');
				});
				
			});
			/*
			测试表头合并单元格
			*/
			
			
			/**
			测试结束
			*/
			<!-- 表单编号（还未确认先以1-7demo） -->
			var EXCYCJT= {
				 "BPA":1//固
				,"BPC":"2"//焊
				,"BPD":"3"//点
				,"BPW":"4"//除胶切筋
				,"BPF":"5"//压膜
				,"BPG":"6"//成型
				,"BPX":"7"//成型后外观全检
				,"BPY":"8"//委外电镀后外观全检
				
			};
			<!-- 工序别 -->
			var GONGXU= {
				 "BPA":"固晶"//固
				,"BPC":"焊线"//焊
				,"BPD":"点胶"//点
				,"BPW":"除胶切筋"//除胶切筋
				,"BPF":"压膜"//压膜
				,"BPG":"成型首件"//成型
				,"BPX":"成型后外观全检"//成型后外观全检
				,"BPY":"委外电镀后外观全检"//终检外观全检
				
			};
			
			<!-- 必填数 -->
			var BTS= {
				 "BPA":3
				,"BPC":7
				,"BPD":5
				,"BPW":5
				,"BPF":5
				,"BPG":13
				,"BPX":0
				,"BPY":0
			};
			
			var qrcode="";
			var FrontTwoString="";
			var gongxu="";
			var datas=new Array();
			$("#keep").attr("disabled", false);//按钮被qi用
			/**
			获取jexcel信息
			*/
			var JiTai = '';
			$("#qr").keypress(function(e){
				var key = e.which;
				if (key == 13) {
					qrcode=$("#qr").val();
					$("#qr").val("");
					FrontTwoString=(qrcode.substring(0,2));//前两位
					
					if(/BP[ACDFGIXYJW]\d{4}/.test(qrcode)){
						qrcode = /BP[ACDFGIXYJW]\d{4}/.exec(qrcode) + "";
						$("#JiTaiid").val(qrcode);
						JiTai=EXCYCJT[qrcode.substring(0,3)];
						console.log(JiTai);
						gongxu=qrcode.substring(0,3);
						console.log(GONGXU[gongxu]);
						
						$("#information").html("当前工站为："+GONGXU[gongxu]);
						console.log($("#information").html());
					}else if(FrontTwoString=='TA'){//TAP8124C02 T5C40781L-03 10 001
						var orders=qrcode.substring(2,qrcode.length);
						console.log(orders);
						cpxh=orders.split(" ");//
						console.log(cpxh);
						$("#orderid").val(cpxh[0]+'-'+cpxh[cpxh.length-1]);
						$("#ChanPinXingHao").val(cpxh[1]);
					}else if(FrontTwoString=='EM'){
						$.ajax({
							type:'POST',
							async: false,
							url:"http://172.31.3.27:84/index.php?s=/scancode/shou_jian/xm",
							data:"qrc="+qrcode,
							dataType:"text",
							success:function(sss){
								$("#JianYanPeople").val(sss);
							}
						});
					}
					
					if($("#JiTaiid").val()!==''&&$("#JianYanPeople").val()!==''&&$("#orderid").val()!=''){
						$("#keep").attr("disabled", false);//按钮被禁用
						$("#keep").attr("class", 'layui-btn  layui-btn-radius layui-btn-normal');//添加禁用渲染
						console.log(JiTai);
						datas=[];
						$.ajax({
							type:'POST',
							async: false,
							url: "http://172.31.3.27:84/index.php?s=/tdled/Infrared",//POST傳一個超長字串到後端
							data:"JiTai="+JiTai,
							dataType:"json",
							success:function(sss){
								console.log(sss);
								var i=0;
								
								for(var k in sss['BY'])
									{
										datas[i]=new Array(6);
										datas[i][0]=sss['BY'][k]['did'];
										datas[i][1]=sss['BY'][k]['type'];
										datas[i][2]=sss['BY'][k]['typedata'];
										datas[i][3]='';
										datas[i][4]='';
										datas[i][5]=$("#JianYanPeople").val();
										i+=1;
									}
								
								console.log(datas);
								
								 $('#mytable').jexcel({ data:datas,
									// Allow column delete 
									allowDeleteColumn:false, 
									// Allow row dragging 
									rowDrag:false,
									columnSorting:false,
									 columns:column, 
									 colHeaders:colHeader,
									 colWidths:colWidth 
								 }); 
								
								
							}
						});
						
					}
				}
			});
			/**
			确认者姓名写入jexcel
			*/
			
			/**
			jexcel基础搭建
			*/
		column=[
	
			{ type:'text', readOnly:true },
			{ type:'text', readOnly:true },
			{ type:'text', readOnly:true },
			{ type:'text', wordWrap:true },
			{ type:'text', wordWrap:true },
			{ type:'text', wordWrap:true },
			
		];		
		var colh = new Array;
		colh[0]=new Array(3);
		colh[0][0]=[
			'id',
			'类型',
			'标准',
			'数值',
			'备注',
			'检验人员',
			
			];
		colHeader=colh[0][0];
						
		colWidth=[
			30,
			180,
			80,
			40,
			40,	
			65,	
			];
		
		$('#mytable').jexcel({ data:"", 
			 // Allow column delete 
			 allowDeleteColumn:false, 
			 // Allow row dragging 
			 rowDrag:false, 
			 columnSorting:false,
			 columns:column, 
			 colHeaders:colHeader, 
			 colWidths:colWidth 
		 }); 
		<!-- -------------------------------------- -->
		
		$("#keep").click(function(){//保存
			var f=1;
			$("#keep").attr("disabled", true);//按钮被禁用
			$("#keep").attr("class", 'layui-btn  layui-btn-radius layui-btn-normal layui-btn-disabled');//添加禁用渲染
			var r=confirm('您确认没问题了吗？');
			
			
			var CXdata10=new Array;
			CXdata10 = $('#mytable').jexcel('getData', false);
			var data=new Array();
			console.log(BTS[gongxu]+gongxu);
				/**for(var i = 0; i < BTS[gongxu]; i++){//循环表格中的二维
					if (CXdata10[i][3]==""){//判断必填值是否为空
						f=0;
						console.log(f);
					}
				}
			if(f==1)
			{*/
				for(var i = 0, j = 0; i < CXdata10.length; i++){//循环表格中的二维
					if (CXdata10[i][3]!=""||CXdata10[i][4]!=""){//判断一行是否全为空，全为空就不存
						data[j]=new Array(2);
						data[j][0]=CXdata10[i][0];
						data[j][1]=CXdata10[i][1];
						data[j][2]=CXdata10[i][2];
						data[j][3]=CXdata10[i][3];
						data[j][4]=CXdata10[i][4];
						data[j][5]=CXdata10[i][5];
						data[j][6]=i+1;
						j++;
					}
				}
				if($("#JiTaiid").val()!=''&&r==true){
					
					$.ajax({
						type:'POST',
						url: "http://172.31.3.27:84/index.php?s=/tdled/Infrared/keepmaintain",//POST傳一個超長字串到後端
						data:"JiTaiid="+$("#JiTaiid").val()+"&orderid="+$("#orderid").val()+"&ChanPinXingHao="+$("#ChanPinXingHao").val()+"&ShuZu="+JSON.stringify(data),
						dataType : "text",
						success: function(data){
							//$("#msg").val(data).css('color','green');
							$("#keep").attr("disabled", false);//按钮被禁用
							$("#keep").attr("class", 'layui-btn  layui-btn-radius layui-btn-normal');//添加禁用渲染
							layer.msg(data);
						}
					}); 
				}
				if(r==false){
					$("#keep").attr("disabled", false);//按钮被禁用
					$("#keep").attr("class", 'layui-btn  layui-btn-radius layui-btn-normal');//添加禁用渲染
					layer.msg('请修改');
				}
			//}
			else{
				//layer.msg('测量值和判断结果必填');
				$("#keep").attr("disabled", false);//按钮被禁用
				$("#keep").attr("class", 'layui-btn  layui-btn-radius layui-btn-normal');//添加禁用渲染
							
			}
		});
		
		
		
		</script>
	</body>
</html>